package com.hn658.base.message.eventbus.util;

import com.hn658.base.message.common.dto.NotificationDTO;
import com.hn658.base.message.notification.msg.entity.MessageEO;
import com.hn658.base.message.notification.notify.entity.NotificationEO;
import com.hn658.framework.shared.utils.BeanMapper;
import com.hn658.framework.shared.utils.JsonMapper;

import java.util.Date;

/**
 * Created by baihai on 2015/11/26.
 */
public class NotifiConvert {

    /**
     * Json序列化器
     */
    private static JsonMapper jsonMapper = JsonMapper.nonEmptyMapper();


    public static NotificationEO convert(MessageEO msg,
                                   String uuid){

        NotificationEO notificationEO = new NotificationEO();

        BeanMapper.copy(msg,notificationEO);

        notificationEO.setNotifyDateTime(new Date().getTime());
        notificationEO.setUuid(uuid);

        return notificationEO;
    }

    public static NotificationDTO convert(MessageEO msg,NotificationEO notificationEO){

        NotificationDTO notificationDTO = new NotificationDTO();

        BeanMapper.copy(notificationEO,notificationDTO);
        notificationDTO.setNotifyData(jsonMapper.toJson(msg));

        return notificationDTO;
    }


}
